import { Component, OnInit, ViewChild, Injector, AfterViewInit, ViewEncapsulation, ElementRef } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { SelectItem } from 'primeng/api';
import { AppComponentBase } from '@shared/common/app-component-base';
import { Table } from 'primeng/table';
import { Paginator, LazyLoadEvent } from 'primeng/primeng';
//import { ExcelModalComponent } from '@app/shared/common/excel-modal/excel-modal.component';
import * as moment from 'moment';
import { BsDatepickerViewMode } from 'ngx-bootstrap/datepicker/models';
import { BsDatepickerConfig, BsDaterangepickerConfig } from 'ngx-bootstrap';
import { finalize } from 'rxjs/operators';
import * as G2 from '@antv/g2';
import { PrimengTableHelper } from '@shared/helpers/PrimengTableHelper';
import { LineInstanceServiceProxy, TaskLineState, ComboboxItemDto, TemplateServiceProxy, AddRequestInput, WorkingTeamProportion, WorkingTeamServiceProxy, CompanyDto, OrganizationUnitServiceProxy, ProductionOrderServiceProxy } from '@shared/service-proxies/service-proxies';
import { ActivatedRoute } from '@angular/router';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';



@Component({
  templateUrl: './order.component.html',
  styleUrls: ['./order.component.css'],
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()]

})
export class OrderComponent extends AppComponentBase  implements OnInit,AfterViewInit {

 

  @ViewChild('dataTable') dataTable: Table;
  @ViewChild('paginatorNormal') paginatorNormal: Paginator;
  @ViewChild('dataTableNormalProductions') dataTableNormalProductions: Table;

  advancedFiltersAreShown: Boolean = false;

  primengTableHelperNormalReport = new PrimengTableHelper();
  paginatorReport = new Paginator();  


  filterTask :string;

  companies : CompanyDto[]= [];
  filterCompany :string= '';

  orderState : ComboboxItemDto[]= [];
  filterOrderState :string = '';

  orderProcessionState : ComboboxItemDto[]= [];
  filterOrderProcessionState :string= '';

  filterDeliveryDate:moment.Moment = null;

  constructor(
    injector: Injector,
    private _organizationUnitServiceProxy : OrganizationUnitServiceProxy,
    private _productionOrderServiceProxy : ProductionOrderServiceProxy

  ) {
    super(injector);         
   
    
  }

  ngOnInit(): void {
    this.initCompanies();
    this.initOrderState();
    this.initOrderProcessionState();
  }

  ngAfterViewInit(): void {
  }

  //初始化公司列表
  initCompanies()
  {
    this._organizationUnitServiceProxy.getAllCompany().subscribe((result)=>this.companies = result);
  }
  //初始化订单状态列表
  initOrderState()
  {
    this._productionOrderServiceProxy.getComboboxItemForProductionState().subscribe((result)=>this.orderState = result);
  }  
  //初始化订单执行状态列表
  initOrderProcessionState()
  {
    this._productionOrderServiceProxy.getComboboxItemForProductionProcessionState().subscribe((result)=>this.orderProcessionState = result);
  }

  
  getReport(event?: LazyLoadEvent) {  

    this.primengTableHelperNormalReport.showLoadingIndicator();  
    this._productionOrderServiceProxy.getProductionOrders(
      this.filterTask,
      this.filterOrderState,
      this.filterOrderProcessionState,
      this.filterDeliveryDate,
      this.filterCompany,
      this.primengTableHelperNormalReport.getSorting(this.dataTableNormalProductions),      
      this.primengTableHelperNormalReport.getSkipCount(this.paginatorNormal, event),
      this.primengTableHelperNormalReport.getMaxResultCount(this.paginatorNormal, event)
    )
    .subscribe((result) => {
      this.primengTableHelperNormalReport.totalRecordsCount = result.totalCount;
      this.primengTableHelperNormalReport.records = result.items;
      this.primengTableHelperNormalReport.hideLoadingIndicator();
    });
  }

  print(qrcode:string,drawingCode:string,quantity:string,specialInfo:string) {
    
  }



}